<?php

include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');

if (!isEmpty(getParam('operation'))) {
    switch (getParam('operation')) {
        case 's':
            save($db);
            break;
        case 'u':
            update($db);
            break;
        case 'd':
            delete($db);
            break;
    }
}

function save($db) {
    $db->query_insert('cllg_charge_policy', array(
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'FK_CAREER' => sqlValue(getParam('FK_CAREER'), 'int'),
        'AMOUNT' => sqlValue(getParam('AMOUNT'), 'double'),
        'PENALTY' => sqlValue(getParam('PENAL'), 'double'),
        'FRECUENCY' => sqlValue(getParam('FRECUENCY'), 'int'),
        'DAY_APPLY' => sqlValue(getParam('DAY_APPLY'), 'int'),
        'MONTH_APPLY' => sqlValue(getParam('MONTH_APPLY'), 'int'),
        'COUNT' => sqlValue(getParam('COUNT'), 'int'),
        'MONEDA' => sqlValue(getParam('MONEDA'), 'int'),
        'CREATED_BY' => sqlValue(getParam('CREATED_BY'), 'date'),
        'CREATED' => sqlValue(getParam('CREATED'), 'date')));
    echo 'SAVED';
}

function update($db) {
    $db->query_update('cllg_charge_policy', array(
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'FK_CAREER' => sqlValue(getParam('FK_CAREER'), 'int'),
        'AMOUNT' => sqlValue(getParam('AMOUNT'), 'double'),
        'PENALTY' => sqlValue(getParam('PENAL'), 'double'),
        'FRECUENCY' => sqlValue(getParam('FRECUENCY'), 'int'),
        'MONTH_APPLY' => sqlValue(getParam('MONTH_APPLY'), 'int'),
        'DAY_APPLY' => sqlValue(getParam('DAY_APPLY'), 'int'),
        'COUNT' => sqlValue(getParam('COUNT'), 'int'),
        'MONEDA' => sqlValue(getParam('MONEDA'), 'int'))
            , 'ID=' . sqlValue(getParam('ID'), 'int'));

    echo "updated";
}

function delete($db) {
    $db->query_delete('cllg_charge_policy', 'ID=' . sqlValue(getParam('ID'), 'int'));
    echo 'DELETED';
}

?>